package com.hmall.cart.listener;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hmall.cart.service.ICartService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Set;

@Component
public class CartListener {

    @Autowired
    private ICartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("cart.clear.queue"),
            exchange = @Exchange(name = "trade.topic",type = ExchangeTypes.TOPIC),
            key = {"order.create"}
    ))
    public void cartClear(String jsonStr) throws JsonProcessingException {
        cartService.removeByUserIdItemIds(jsonStr);
    }
}
